package com.android.gpuimage;

import android.annotation.SuppressLint;

/**
 * 移轴镜滤镜
 */
@SuppressLint("WrongCall")
public class GPUImageTiltShiftFilter extends GPUImageFilterGroup {

    private GPUImageTiltShiftSubFilter mSubFilter;
    private GPUImageGaussianBlurFilter mBlurFilter;

    public GPUImageTiltShiftFilter(int defaultX, int defaultY) {
        super(null);
        mBlurFilter = new GPUImageGaussianBlurFilter(2.0f);
        mSubFilter = new GPUImageTiltShiftSubFilter(defaultX, defaultY);
        addFilter(mBlurFilter);
        addFilter(mSubFilter);
    }
    public void setFocusPoint(float x, float y) {
        mSubFilter.setFocusPoint(x, y);
    }

    public void setFocusWidth(float width) {
        mSubFilter.setFocusWidth(width);
    }

    public float getFocusWidth() {
        return mSubFilter.getFocusWidth();
    }

    public boolean scaleFocusWidth(float scale) {
        return mSubFilter.scaleFocusWidth(scale);
    }

    public float getPointXPixel() {
        return mSubFilter.getPointXPixel();
    }

    public float getPointYPixel() {
        return mSubFilter.getPointYPixel();
    }

    public float getFocusPointX() {
        return mSubFilter.getFocusPointX();
    }

    public float getFocusPointY() {
        return mSubFilter.getFocusPointY();
    }

    public float getAngle() {
        return mSubFilter.getAngle();
    }

    public float getRotationXPixel() {
        return mSubFilter.getRotationXPixel();
    }

    public float getRotationYPixel() {
        return mSubFilter.getRotationYPixel();
    }

    public void setFoucsFallOffRate(float rate) {
        mSubFilter.setFoucsFallOffRate(rate);
    }
    
    public void setBlurSize(float value) {
        mBlurFilter.setBlurSize(value);
    }

    public float getBlurSize() {
        return mBlurFilter.getBlurSize();
    }
    
    public void setAngle(float value, float x, float y) {
        mSubFilter.setAngle(value, x, y);
    }

    public void setPressed(boolean value) {
        mSubFilter.setPressed(value);
    }

    public void setShowTIpShadow(boolean show) {
        mSubFilter.setShowTIpShadow(show);
    }

    public boolean isPressed() {
        return mSubFilter.isPressed();
    }

    public void copy(GPUImageTiltShiftFilter filter) {
        onOutputSizeChanged(filter.getOutputWidth(), filter.getOutputHeight());
        setFocusPoint(filter.getPointXPixel(), filter.getPointYPixel());
        setFocusWidth(filter.getFocusWidth());
        setBlurSize(filter.getBlurSize());
        setAngle(filter.getAngle(), filter.getRotationXPixel(), filter.getRotationYPixel());
    }

    public void copyFromData(float[] data) {
        if (data != null && data.length > 8) {
            try {
                onOutputSizeChanged((int) data[7], (int) data[8]);
            } catch (Exception e) {
                e.printStackTrace();
            }
            setFocusPoint(data[0], data[1]);
            setFocusWidth(data[2]);
            setBlurSize(data[3]);
            setAngle(data[4], data[5], data[6]);
        }
    }

    public float[] copyData() {
        float[] ret = new float[9];
//        ret[0] = getFocusPointX();
//        ret[1] = getFocusPointY();
        ret[0] = getPointXPixel();
        ret[1] = getPointYPixel();
        ret[2] = getFocusWidth();
        ret[3] = getBlurSize();
        ret[4] = getAngle();
        ret[5] = getRotationXPixel();
        ret[6] = getRotationYPixel();
        ret[7] = getOutputWidth();
        ret[8] = getOutputHeight();
        return ret;
    }
}
